package com.cloud.common.data.mybatis;


import com.baomidou.mybatisplus.extension.plugins.OptimisticLockerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
import com.baomidou.mybatisplus.extension.plugins.PerformanceInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


/**
 * @Author Aijm
 * @Description 集成mybatisplus
 * @Date 2019/5/8
 */
@Configuration
@MapperScan("com.cloud.*.mapper")
public class MybatisPlusConfig {


    /**
     *  分页插件
     * @return
     */
    @Bean
    public PaginationInterceptor paginationInterceptor() {
        PaginationInterceptor paginationInterceptor = new PaginationInterceptor();
        paginationInterceptor.setLimit(10);
        return paginationInterceptor;
    }


    /**
     * 性能分析拦截器，不建议生产使用
     */
    @Bean
    @ConditionalOnExpression("${mybatis-plus.performanceInterceptor.enabled:false}")
    public PerformanceInterceptor performanceInterceptor(){
        return new PerformanceInterceptor();
    }

    /**
     * 乐观锁
     * @return
     */
    @Bean
    public OptimisticLockerInterceptor optimisticLockerInterceptor() {
        return new OptimisticLockerInterceptor();
    }
}
